package com.yijiu.utils;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;

import android.content.Context;
import android.widget.ImageView;

import com.yijiu.trb.R;

public class ConvertUtils
{
	public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	private static DecimalFormat unitFormat = new DecimalFormat("0.00");
	
	public static class FeedUnitType
	{
		public static final int FEED_ML = 1;
		public static final int FEED_US = 2;
		public static final int FEED_UK = 3;
	}
	
	public static int dip2px(Context context, float dipValue)
	{
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (dipValue * scale + 0.5f);
	}
	public static int px2dip(Context context, float pxValue)
	{
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (pxValue / scale + 0.5f);
	}
	public static String[] lengthMetricToImperial(String cm)
	{
		double getcm = 0;
		if (cm.trim().length() != 0)
		{
			getcm = Double.parseDouble(cm);
		}
		String[] imperial = new String[2];
		imperial[0] = String.valueOf((int) (getcm / 12));
		imperial[1] = String.valueOf(unitFormat.format((double) ((getcm % 12) * 0.3937)));
		return imperial;
	}
	public static String lengthImperialToMetric(String feet, String inches)
	{
		double dfeet = 0;
		double dinches = 0;
		if (feet.trim().length() != 0)
		{
			dfeet = Double.parseDouble(feet) * 12;
		}
		if (inches.trim().length() != 0)
		{
			dinches = Double.parseDouble(inches) / 0.3937;
		}
		return String.valueOf(unitFormat.format((double) (dfeet + dinches)));
	}
	public static String[] weightMetricToImperial(String kg)
	{
		double getkg = 0;
		if (kg.trim().length() != 0)
		{
			getkg = Double.parseDouble(kg);
		}
		String[] imperial = new String[2];
		imperial[0] = String.valueOf((int) (getkg / 16));
		imperial[1] = String.valueOf(unitFormat.format((double) ((getkg % 16) * 35.27)));
		return imperial;
	}
	public static String weightImperialToMetric(String lbs, String oz)
	{
		double dlbs = 0;
		double doz = 0;
		if (lbs.trim().length() != 0)
		{
			dlbs = Double.parseDouble(lbs) * 16;
		}
		if (oz.trim().length() != 0)
		{
			doz = Double.parseDouble(oz) / 35.27;
		}
		return String.valueOf(unitFormat.format((double) ((dlbs + doz))));
	}
	public static float pixelsToSp(Context context, Float px)
	{
		float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
		return px / scaledDensity;
	}
	public static float spToPixel(Context context, Float sp)
	{
		float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
		return sp * scaledDensity;
	}
	public static String LeftPad_Tow_Zero(int str)
	{
		java.text.DecimalFormat format = new java.text.DecimalFormat("00");
		return format.format(str);
	}
	public static boolean isNull(String str)
	{
		if (str.length() == 0)
		{
			return true;
		}
		return false;
	}
	public static void checkBankIcon(String str, ImageView imageView)
	{
		if (str.contains("中国银行"))
			imageView.setImageResource(R.drawable.zg_bank);
		else if (str.contains("招商银行"))
			imageView.setImageResource(R.drawable.zs_bank);
		else if (str.contains("农业银行"))
			imageView.setImageResource(R.drawable.ny_bank);
		else if (str.contains("工商银行"))
			imageView.setImageResource(R.drawable.gs_bank);
		else if (str.contains("兴业银行"))
			imageView.setImageResource(R.drawable.xy_bank);
		else if (str.contains("建设银行"))
			imageView.setImageResource(R.drawable.js_bank);
		else if (str.contains("人民银行"))
			imageView.setImageResource(R.drawable.rm_bank);
		else if (str.contains("交通银行"))
			imageView.setImageResource(R.drawable.jt_bank);
		else if (str.contains("中信银行"))
			imageView.setImageResource(R.drawable.zx_bank);
	}
	public static String checkTimeUnit(String str)
	{
		if (str != null)
		{
			if (str.contains("D"))
				return "天";
			else if (str.contains("M") || str.contains("W"))
				return "个月";
			else if (str.contains("Y"))
				return "年";
		}
		return "未知";
	}
	public static String checkRealNameStatus(String str)
	{
		if (str != null)
		{
			if (str.contains("IS"))
			{
				return "已认证";
			}
			else if (str.contains("NO"))
			{
				return "认证未通过";
			}
			else if (str.contains("IN"))
			{
				return "认证中";
			}
			else if (str.contains("N"))
			{
				return "未认证";
			}
			else if (str.contains("null"))
			{
				return "未认证";
			}
			else
			{
				return "未知";
			}
		}
		return "未知";
	}
}
